<?php
include("config/session.php");
include("./config/config.inc.php");
include("./config/QuickMySQL.php");
include("./config/function.inc.php");

class CSendEMailLast extends PageBase
{
	/* 加载页面 */
	function OnPageLoad(){
		include("./class/template.inc");
		
		$tpl = new Template("./ui/");
		
		// 显示普通界面
		$tpl->set_file("main", "sendemail-last.html");
		$tpl->pparse("mains", "main");
		
	}
	/*加载数据*/
	function OnGetData(){
		$ret = array("total" => 0, "rows" => array());
		$cnn = new QuickMySQL();
		if( $cnn->mysql ){
			/*连接数据库成功，查询相关数据*/
			$page = (int)$_POST["page"] - 1;
			$pagesize = (int)$_POST["rows"];
			if( $page < 0 ) $page = 0;
			if( $pagesize < 1 ) $pagesize = 1;
			$start = $page * $pagesize;
			/* 构造查询语句 */
			$sql = "select a.sm_to, b.addr, c.sname, a.sm_subject, a.sm_run, a.sm_lastday, "
				. " a.sm_cycle, a.sm_success, a.sm_failure, a.sm_firstdt, a.sm_lastdt "
				. " from t_sendemail_notify as a left join t_email_list as b on a.m_no = b.id "
				. " left join t_list_user as c on a.sm_to = c.tname "
				. " order by a.sm_to desc limit {$start},{$pagesize}";
			if( $res = mysql_query($sql, $cnn->mysql) ){
				while( $row = mysql_fetch_row($res) ){
					array_push($ret["rows"], array(
								"rawto" => $row[0]
								, "from" => $row[1]
								, "to" => $row[2]
								, "subject" => $row[3]
								, "run" => $row[4]
								, "day" => $row[5]
								, "cycle" => $row[6]
								, "sucess" => $row[7]			
								, "failure" => $row[8]			
								, "firstdt" => $row[9]			
								, "lastdt" => $row[10]			
								));	
				} 				
				mysql_free_result($res);
			}
			/*查询总个数*/
			$ret["total"] = $cnn->getTableCount("t_sendemail_group");
		}
		
		$ret_json = json_encode($ret);
		echo $ret_json;
	}
}

$cc = new CSendEMailLast();

?>